package com.gzg.userservice.controller;
import com.gzg.userservice.domain.dto.LoginDTO;
import com.gzg.userservice.domain.dto.PageDTO;
import com.gzg.userservice.domain.po.User;
import com.gzg.userservice.domain.vo.Result;
import com.gzg.userservice.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final IUserService userService;

    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        return userService.register(user);
    }

    @ApiOperation("用户登录接口")
    @PostMapping("/login")
    public Result login(@RequestBody LoginDTO loginDTO){
        return userService.login(loginDTO);
    }

    @ApiOperation("分页查询")
    @PutMapping("users")
    public Result queryUsersPage(@RequestBody PageDTO pageDTO){
        return userService.queryUsersPage(pageDTO);
    }

    @ApiOperation("根据id查询用户")
    @GetMapping("/{userId}")
    public Result queryUserById(@PathVariable("userId") Long id){
        return userService.queryUserById(id);
    }

    @ApiOperation("修改用户信息")
    @PutMapping("/update")
    public Result updateUser(@RequestBody User user){
        return userService.updateUser(user);
    }

    @ApiOperation("密码重置")
    @PostMapping("/reset-password")
    public Result resetPassword(@RequestBody User user){
        return userService.resetPassword(user);
    }

}
